package com.pdfbox.sample.quickstart;

import java.io.File;
import java.io.IOException;

import org.apache.pdfbox.Loader;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.font.PDType1Font;
import org.apache.pdfbox.text.PDFTextStripper;

public class _9ReadText {

  public static void main (String args[]) throws IOException {
    String existFileName = "E:/PdfBox_Examples/周报_add_multiple_text.pdf";

    // 第1步:加载现有PDF文档
    File file = new File(existFileName);
//    PDDocument document = PDDocument.load(file);
    PDDocument document = Loader.loadPDF(file);

    // 第2步:实例化PDFTextStripper类
    PDFTextStripper pdfStripper = new PDFTextStripper();

    // 第3步:检索文本
    String text = pdfStripper.getText(document);
    System.out.println(text);

    // 第4步:关闭文档
    document.close();

    System.out.println("read " + existFileName + " success");
  }

}
